import math
from pygame.locals import *


class OnScreenObject():
    #Necessary functions
    """
    Class of objects that are represented on screen.
    """
    def __init__(self, x = 0, y = 0, h = 0):
        """Creates new OnScreenObject.
        x = x Coord
        y = y Coord
        h = heading
        """
        self.x = x
        self.y = y
        self.h = h

    def __str__(self):
        """Returns (x, y)
        """
        return "("+ str(self.x)+ ", "+ str(self.y)+ ")"


    #Queries
    def getX(self):
        """Returns x
        """
        return self.x

    def getY(self):
        """Returns y
        """
        return self.y

    def getH(self):
        """Returns H
        """
        return self.h

    #Commands
        #Set Variables directly
    def setX(self, x):
        """Sets x coord to x
        """
        self.x = x

    def setY(self, y):
        """Sets y coord to y
        """
        self.y = y

    def setH(self, h):
        """Sets heading to h
        """
        self.h = self.fixH(h)

        #Movement
    def lt(self, deg):
        """Turn deg amount counter-clockwise
        """
        self.h -= deg

    def rt(self, deg):
        """Turn deg amount clockwise
        """
        self.lt(-deg)
        
    def fd(self, dist):
        """Move dist forward
        """
        tempH = 360 - self.h
        tempH = self.fixH(tempH + 90)

        self.x += dist * math.cos(math.radians(tempH))
        self.y += dist * math.sin(math.radians(tempH))


            
    def bk(self, dist):
        """Move dist backward
        """
        self.fd(-dist)

    #Private / Helper methods
    def fixH(self, h):
        """Ensure h is in [0-360)
        """
        h %= 360
        if h<0:
            h += 360
        return h
